package com.liveneo.stoat.common.page;

import com.github.pagehelper.PageInfo;

/**
 * 生成界面上的分页组件
 */
public class PageUtils {


    //<ul><li class="disabled"><a href="javascript:">&#171; 上一页</a></li><li class="active"><a href="javascript:">1</a></li><li><a href="javascript:page(2,15)">2</a></li><li><a href="javascript:page(3,15)">3</a></li><li><a href="javascript:page(2,15)">下一页 &#187;</a></li><li class="disabled controls"><a href="javascript:void(0);">当前第 <input type="text" value="1" onkeypress="var e=window.event||this;var c=e.keyCode||e.which;if(c==13)page(this.value,15);" onclick="this.select();"/> 页 / 共 3 页， 共 33 条</a></li></ul>
    public static String pageStr (PageInfo pageInfo) {

    	if(pageInfo == null){
    		return "";
    	}
        StringBuilder sb = new StringBuilder("<ul>");
        
        sb.append("<div class=\"dataTables_info\">当前第 ");
        sb.append("<input type=\"text\" class=\"input-text\" style=\"width:30px;\" maxLength=\"6\" value=\"");
        sb.append(pageInfo.getPageNum());
        sb.append("\" onkeypress=\"var e=window.event||this;var c=e.keyCode||e.which;if(c==13)page(this.value,");
        sb.append(pageInfo.getPageSize()).append(");\" onclick=\"this.select();\"/>");
        sb.append(" 页 / 共 "+pageInfo.getPages()+" 页， 共 "+pageInfo.getTotal()+" 条</div>");              
	
        
        sb.append("<div class=\"dataTables_paginate paging_simple_numbers\">");
        
        //判断当前页是不是首页
        if (pageInfo.isIsFirstPage()) {
            sb.append("<a class=\"paginate_button disabled\">首页</a>");
            sb.append("<a class=\"paginate_button previous disabled\">上一页</a>");
        } else {
            sb.append("<a class=\"paginate_button\" href=\"javascript:page(1");
            sb.append(",");
            sb.append(pageInfo.getPageSize()).append(")\">首页</a>");
            sb.append("<a class=\"paginate_button previous\" href=\"javascript:page(");
            sb.append(pageInfo.getPrePage()).append(",");
            sb.append(pageInfo.getPageSize()).append(")\">&#171; 上一页</a>");
        }

        for (int i = 0; i < pageInfo.getNavigatepageNums().length; i++) {
            int pageNum = pageInfo.getNavigatepageNums()[i];
            if (pageInfo.getPageNum() == pageNum) {
                sb.append("<span><a class=\"paginate_button current\">");
                sb.append(pageNum).append("</a></span>");
            } else {
            	sb.append("<span><a class=\"paginate_button\" href=\"javascript:page(");
                sb.append(pageNum).append(", ");
                sb.append(pageInfo.getPageSize()).append(")\">");
                sb.append(pageNum).append("</a></span>");
            }
        }

        //判断是否是尾页
        if (pageInfo.isIsLastPage()  || pageInfo.getPages() == 0) {
            sb.append("<a class=\"paginate_button next disabled\">下一页 &#187;</a>");
            sb.append("<a class=\"paginate_button disabled\">末页</a>");
        } else {
            sb.append("<a class=\"paginate_button next\" href=\"javascript:page(");
            sb.append(pageInfo.getNextPage()).append(",");
            sb.append(pageInfo.getPageSize()).append(")\">下一页 &#187;</a>");
            sb.append("<a class=\"paginate_button\" href=\"javascript:page(");
            sb.append(pageInfo.getPages()).append(",");
            sb.append(pageInfo.getPageSize()).append(")\">末页</a>");
        }
   
        sb.append("</div></div>");

        return sb.toString();

    }


}

/**
 * 分页html
 * <div class="dataTables_wrapper">
			<div class="dataTables_info">
				当前第1页 / 共 124 页， 共 1232 条              
			</div>
			<div class="dataTables_paginate paging_simple_numbers">
				<a class="paginate_button disabled current">首页</a>
				<a class="paginate_button previous disabled current">上一页</a>
				<span><a class="paginate_button current">1</a></span>
				<span><a class="paginate_button">2</a></span>
				<span><a class="paginate_button">3</a></span>
				<span><a class="paginate_button">4</a></span>
				<a class="paginate_button next disabled">下一页</a>
				<a class="paginate_button disabled">末页</a>
			</div>
		</div>
		
		*/
